package com.zjsd.sqeybusiness.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.zjsd.sqeybusiness.domain.CompanyMainCategory;
import com.zjsd.sqeybusiness.service.ICompanyMainCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 企业主营分类Controller
 *
 * @author Zheng
 * @date 2020-11-05
 */
@RestController
@RequestMapping("/jph/companyMainCategory")
public class CompanyMainCategoryController extends BaseController
{
    @Autowired
    private ICompanyMainCategoryService companyMainCategoryService;

    /**
     * 查询企业主营分类列表
     */
    @PreAuthorize("@ss.hasPermi('jph:companyMainCategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(CompanyMainCategory companyMainCategory)
    {
        startPage();
        List<CompanyMainCategory> list = companyMainCategoryService.selectCompanyMainCategoryList(companyMainCategory);
        return getDataTable(list);
    }

    /**
     * 导出企业主营分类列表
     */
    @PreAuthorize("@ss.hasPermi('jph:companyMainCategory:export')")
    //@Log(title = "企业主营分类", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CompanyMainCategory companyMainCategory)
    {
        List<CompanyMainCategory> list = companyMainCategoryService.selectCompanyMainCategoryList(companyMainCategory);
        ExcelUtil<CompanyMainCategory> util = new ExcelUtil<CompanyMainCategory>(CompanyMainCategory.class);
        return util.exportExcel(list, "companyMainCategory");
    }

    /**
     * 获取企业主营分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('jph:companyMainCategory:query')")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return AjaxResult.success(companyMainCategoryService.selectCompanyMainCategoryById(categoryId));
    }

    /**
     * 新增企业主营分类
     */
    @PreAuthorize("@ss.hasPermi('jph:companyMainCategory:add')")
    //@Log(title = "企业主营分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CompanyMainCategory companyMainCategory)
    {
        return toAjax(companyMainCategoryService.insertCompanyMainCategory(companyMainCategory));
    }

    /**
     * 修改企业主营分类
     */
    @PreAuthorize("@ss.hasPermi('jph:companyMainCategory:edit')")
    //@Log(title = "企业主营分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CompanyMainCategory companyMainCategory)
    {
        return toAjax(companyMainCategoryService.updateCompanyMainCategory(companyMainCategory));
    }

    /**
     * 删除企业主营分类
     */
    @PreAuthorize("@ss.hasPermi('jph:companyMainCategory:remove')")
    //@Log(title = "企业主营分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(companyMainCategoryService.deleteCompanyMainCategoryByIds(categoryIds));
    }
}
